package com.msmall.community.bbs.action.html;

import com.msmall.base.util.ConstantAjax;
import com.msmall.base.util.Constants;
import com.msmall.community.bbs.model.Favorite;
import com.msmall.community.bbs.service.FavoriteManager;

public class FavoriteAction extends BBSBaseAction {

	private static final long serialVersionUID = 1609224827591100456L;

	private Long favoriteId;
	
	private Favorite favorite;
	
	private FavoriteManager favoriteManager;
	
	/**
	 * 进入我的收藏首页
	 * @return
	 */
	public String index(){
		page.setPageSize(Constants.PAGINATION_SIZE_HTML);
		favoriteManager.getPagination(page, getUserid());
		return SUCCESS;
	}
	/**
	 * 添加收藏
	 * @return
	 */
	public String save(){
		StringBuffer buffer = new StringBuffer();
		buffer.append(ConstantAjax.RETURN_PRE);
		try{
			favoriteManager.save(getUserid(), tid);
			buffer.append(this.createResult("true"))
			.append(ConstantAjax.CONTENT_PRE)
			.append(getText("html.bbs.topic.favorite.add.success"))
			.append(ConstantAjax.CONTENT_SUFF);
		}catch(Exception e){
			buffer.append(this.createResult("false"))
			.append(ConstantAjax.CONTENT_PRE)
			.append(getText("html.bbs.topic.favorite.add.error"))
			.append(ConstantAjax.CONTENT_SUFF);
		}
		buffer.append(ConstantAjax.RETURN_SUFF);
		message = buffer.toString();
		return SUCCESS;
	}
	/**
	 * 删除收藏
	 * @return
	 */
	public String delete(){
		StringBuffer buffer = new StringBuffer();
		buffer.append(ConstantAjax.RETURN_PRE);
		try{
			favoriteManager.remove(Favorite.class, favoriteId);
			buffer.append(this.createResult("true"));
		}catch(Exception e){
			buffer.append(this.createResult("false"));
		}
		buffer.append(ConstantAjax.RETURN_SUFF);
		message = buffer.toString();
		return SUCCESS;
	}
	
	public Long getFavoriteId() {
		return favoriteId;
	}
	public void setFavoriteId(Long favoriteId) {
		this.favoriteId = favoriteId;
	}
	public Favorite getFavorite() {
		return favorite;
	}
	public void setFavorite(Favorite favorite) {
		this.favorite = favorite;
	}
	public void setFavoriteManager(FavoriteManager favoriteManager) {
		this.favoriteManager = favoriteManager;
	}
}
